package com.xyoto.community.service.impl;

/**
 * @author coderFu
 * @create 2022/2/27
 */

import com.xyoto.community.cache.CacheInstruction;
import com.xyoto.community.cache.UserCache;
import com.xyoto.community.constant.DeleteStatus;
import com.xyoto.community.entity.main.Dynamic;
import com.xyoto.community.mapper.main.DynamicMapper;
import com.xyoto.community.mapper.main.UserMapper;
import com.xyoto.community.service.DynamicCacheService;
import com.xyoto.community.utils.RedisCommonUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@SpringBootTest
public class EmptyDynamicHotScore {

    @Autowired
    RedisCommonUtils redisCommonUtils;

    @Autowired
    UserMapper userMapper;

    @Autowired
    private DynamicCacheService dynamicCacheService;

    @Autowired
    private DynamicMapper dynamicMapper;


    
    @Test
    public void test(){
        List<String> list = new ArrayList<>();
        list.add("topic_user_hot_beauty_fashion");
        list.add("topic_user_hot_daily_clock_in");
        list.add("topic_user_hot_daily_life");
        list.add("topic_user_hot_game_group");
        list.add("topic_user_hot_lost_and_found");
        list.add("topic_user_hot_photograph_and_make_friends");
        list.add("topic_user_hot_q_a_bar");
        list.add("topic_user_hot_second_hand_trade");
        list.add("topic_user_hot_show_love");
        list.add("topic_user_hot_whisper_bar");

        for (int i=0; i<list.size(); i++){
            Set<Object> set = redisCommonUtils.rangeByZSet(list.get(i),0,-1);
            for (Object object : set) {
               Integer userId = Integer.parseInt(object.toString());
               redisCommonUtils.zSet(list.get(i), userId,0.0);
            }
        }
    }


    @Test
    public void test2(){
        Set<Object> set = redisCommonUtils.rangeByZSet(CacheInstruction.USER_RANK, 0, -1);
        for (Object object : set) {
            Integer userId = Integer.parseInt(object.toString());
            redisCommonUtils.zSet(CacheInstruction.USER_RANK, userId,0.0);
        }
    }

    /**
     * 清空铭牌
     */

    @Test
    public void test3(){
        List<Integer> userIds = new ArrayList<>();

        //userIds.add(6);
        userIds.add(15);
        userIds.add(8);
        userIds.add(11);
        userIds.add(18);
        userIds.add(22);
        userIds.add(9);
        userIds.add(17);
        userIds.add(21);
        userIds.add(48);
        userIds.add(14);
        userIds.add(24);
        userIds.add(84);
        userIds.add(10);

        for (int i= 0; i<userIds.size(); i++){
            UserCache userCache = userMapper.getUserCache(userIds.get(i));
            if (userCache != null){
              //  System.out.println(userCache);
                redisCommonUtils.hset(CacheInstruction.USER_CACHE,userCache.getId().toString(),userCache);
            }
        }



    }

    /**
     * 将最新的500条加入到redsi
     * @author 廖振辉
     * @return {@link}
     */
    @Test
    public void updateTotalDynamic2Cache(){
        List<Dynamic> dynamicList = dynamicMapper.getAllDynamic(DeleteStatus.NO);
        for (Dynamic dynamic : dynamicList) {
            dynamicCacheService.saveDynamic2LatestDynamicIdSet(dynamic);
        }
    }




}
